import time


def get_now_time():
    return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())


def route(rule):
    print(f"in route {get_now_time()} {rule}")

    def decorator(f):
        print(f"in decorator {get_now_time()} {f.__name__} {rule}")
        return f
    return decorator


@route("/index")
def index():
    print(f"in index {get_now_time()}")


def get_id():
    print(f"in get id {get_now_time()}")


if __name__ == '__main__':
    print(f"in main {get_now_time()}")


class Pet:

    def __init__(self, name):
        self.name = name

    def move(self):
        print(f"{self.name}<{self.__class__.__name__}> is moving")


class Cat(Pet):

    def __init__(self, name, color):
        super(Cat, self).__init__(name)  # Pet.__init__(self, name)
        self.color = color

    def move(self):
        super().move()

    def yell(self):
        print(f"the {self.color} {self.name}<{self.__class__.__name__}> miaowing")


cat = Cat("XiaoHua", "yellow")
cat.move()
cat.yell()


class Pet:
    def __init__(self, health):
        self.health = health
        print(f"Pet {self.health}")

    def yell(self, name):
        print(f"{name} yell")


class Dog:
    def __new__(cls, *args, **kwargs):
        return object.__new__(Pet, *args, **kwargs)

    def __init__(self, health):
        self.health = health
        print(f"Dog {self.health}")

    def yell(self, name):
        print(f"dog {name} yell")


dog = Dog("good")
print(type(dog))
dog.yell("XiaoHuang")
dog.__init__("good")


class Person:
    # def __del__(self):
    #     print("Person dead")

    def live(self):
        print("Im live")


person = Person()
# del person
person.live()
print("in process")


class XiaoMing:
    pass


class Person:
    def __new__(cls, *args, **kwargs):
        return object.__new__(XiaoMing, *args, **kwargs)


class Dog(Person):
    pass


print(type(Dog()))


class Person:

    def __init__(self, name, age):
        self.name = name
        self.age = age

    # def __getattr__(self, item):
    #     if 'ag' in item or 'ae' in item or 'ge' in item:
    #         return self.age
    #
    # def __setattr__(self, key, value):
    #     print(key, value)
    #
    def __delattr__(self, item):
        print(item)

    def __getattribute__(self, item):
        print(item)


guang = Person("XiaoGuang", 25)
print(guang.__len__)
